package br.com.gip.repository.dao;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.gip.repository.model.HistoricoArtefato;
import br.com.gip.repository.persistence.HibernateDao;

@Repository
@Transactional
public class HistoricoArtefatoDao extends HibernateDao<HistoricoArtefato, Long> {

	private static final long serialVersionUID = -6684787558645046467L;

	@SuppressWarnings("unchecked")
	public List<HistoricoArtefato> findByIdArtefato(Long idArtefato) {
		this.getCurrentSession().clear();
		Criteria criteria = this.getCurrentSession().createCriteria(HistoricoArtefato.class, "a");
		criteria.add(Restrictions.eq("artefato.id", idArtefato));
		return (List<HistoricoArtefato>) criteria.list();
	}
	
	@SuppressWarnings("unchecked")
	public List<HistoricoArtefato> findByFilter(String nomeArtefato) {
		this.getCurrentSession().clear();
		Criteria criteria = this.getCurrentSession().createCriteria(HistoricoArtefato.class, "a");
		
		if (!StringUtils.isBlank(nomeArtefato)) {
			criteria.add(Restrictions.eq("artefato.nome", nomeArtefato));	
		}
		
		
		return (List<HistoricoArtefato>) criteria.list();
	}
	
	
}